<template>
  <div class="body">
    <div><back></back></div>

    <h2>我的地址</h2>

    <div>
      <van-address-list
        v-model="chosenAddressId"
        :list="list"
        default-tag-text="默认"
        add-button-text="添加地址"
        @add="onAdd"
        @edit="onEdit"
        @click-item="clickItem"
      />
    </div>
    <div class="b">1</div>
    <van-back-top right="2.5vw" bottom="18.5vh" />
  </div>
</template>

<script setup>
import { ref, onMounted } from "vue";

import { useRoute, useRouter } from "vue-router";

import { useAddrStore } from "@/stores/addr.js";

// 返回按钮
import back from "@/components/Back.vue";

const addrS = useAddrStore();

const route = useRoute();
const router = useRouter();

let list = ref([]);

function clickItem(e) {
  addrS.defaultAddr = {
    id: e.id,
    name: e.name,
    tel: e.tel,
    areaCode: e.areaCode,
    addressDetail: e.addressDetail,
    isDefault: e.isDefault,
  };
}

const chosenAddressId = ref("1");

onMounted(() => {
  list.value = addrS.addrList;
});

function onAdd() {
  router.push({
    path: "/users/location/newaddr",
  });
}
function onEdit() {
  router.push({
    path: "/users/location/changeaddr",
  });
}
</script>

<style lang="less" scoped>
h2 {
  line-height: 1;
  font-weight: 600;
  margin-bottom: 2.133vw;
  margin-left: 5.067vw;
}

:deep(.van-address-list__bottom) {
  background-color: #fff;
  bottom: 14vw;
  padding: 0;
  width: 90%;
  left: 5vw;
}
:deep(.van-address-list__add) {
  margin: 0;
}
:deep(.van-button--round) {
  border-radius: 2.333vw;
}
:deep(.van-address-item) {
  box-shadow: 0 0 1.6vw #999;
}
:deep(.van-address-item:not(:last-child)) {
  margin-bottom: 7.667vw;
}
:deep(.van-address-list) {
  padding-left: 5.067vw;
  padding-right: 5.067vw;
}
:deep(.van-button--round) {
  background-color: rgb(255, 60, 80);
  border: none;
}
:deep(.van-radio__icon--checked .van-icon) {
  background-color: rgb(255, 60, 80);
  border: none;
}

:deep(.van-tag--primary) {
  background-color: rgb(255, 60, 80);
}
.body {
  padding-bottom: 6vh;
}
.b {
  position: fixed;
  width: 100%;
  height: 15.667vw;
  bottom: 0;
  left: 0;
  background-color: #fff;
  color: #fff;
}
</style>
